package com.mcglib.flac
{
	import com.mcglib.flac.FlacComponent;
	
	import flash.display.MovieClip;
	import flash.events.MouseEvent;

	public class McButton extends FlacComponent
	{
		private var outFrame:int =  1;
		
		private var overFrame:int = 2;
		
		private var downFrame:int = 3;
		
		private var unenabledFrame:int = 4;
		
		private var _enabled:Boolean = true;
		
		private var _isOver:Boolean = false;
		
		private var _mc:MovieClip;
		
		public function McButton(mc:MovieClip,label:Boolean=false)
		{
			if(label){
				mc.gotoAndStop("out");
				outFrame = mc.currentFrame;
				
				mc.gotoAndStop("over");
				overFrame = mc.currentFrame;
				
				mc.gotoAndStop("down");
				downFrame =  mc.currentFrame;
				
				mc.gotoAndStop("unenabled");
				unenabledFrame = mc.currentFrame;
			}
			
			mc.mouseChildren = false;
			mc.buttonMode = true;
			mc.gotoAndStop(outFrame);
		
			mc.addEventListener(MouseEvent.MOUSE_OVER,onMouseOver);
			mc.addEventListener(MouseEvent.MOUSE_OUT,onMouseOut);
			mc.addEventListener(MouseEvent.MOUSE_DOWN,onMouseDown);
			mc.addEventListener(MouseEvent.MOUSE_UP,onMouseUp);
			
			_mc = mc;
		}
		
		
		
		public function get enabled():Boolean
		{
			return _enabled;
		}

		public function set enabled(value:Boolean):void
		{
			_enabled = value;
			if(!value){
				_mc.gotoAndStop(unenabledFrame);
			}else{
				_mc.gotoAndStop(outFrame);
			}
		}

		private function onMouseOver(e:MouseEvent):void{
			_isOver = true;
			if(_enabled){
				_mc.gotoAndStop(overFrame);
			}
		}
		
		private function onMouseOut(e:MouseEvent):void{
			_isOver = false;
			if(_enabled){
				_mc.gotoAndStop(outFrame);
			}
		}
		
		private function onMouseDown(e:MouseEvent):void{
			if(_enabled){
				_mc.gotoAndStop(downFrame);
			}
		}
		
		private function onMouseUp(e:MouseEvent):void{
			if(_enabled){
				_mc.gotoAndStop(overFrame);
			}
		}
	}
}